package day05;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定义私有属性: String name; 
 * int age; 
 * String gender; 
 * int salary; 
 * Date hiredate;//入职时间
 * 
 * 定义构造方法，以及属性get,set方法. 
 * 定义toString方法，格式如:
 * 姓名:张三,年龄:25,性别:男,薪资:5000,入职时间:2006-02-15
 * 
 * 定义equals方法，要求名字以及年龄相同，则认为内容一致。
 * 
 * 实现Comparable接口，并重写抽象方法comparaTo()，比较规则为年龄小的人小。
 * 
 * @author Bonnie
 *
 */
public class Emp implements Comparable<Emp>{
	

	private String name;
	private int age;
	private String gender;
	private int salary;
	private Date hiredate;

	public Emp(String name, int age, String gender, int salary, Date hiredate) {
		super();
		this.name = name;
		this.age = age;
		this.gender = gender;
		this.salary = salary;
		this.hiredate = hiredate;
	}

	public Emp() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	public int compareTo(Emp o) {
		// TODO Auto-generated method stub
		return age - o.age;
	}

	@Override
	public String toString() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return "姓名：" + name + ", 年龄：" + age + ", 性别：" + gender + ", 工资：" + salary + ", 入职日期：" + sdf.format(hiredate);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + age;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Emp other = (Emp) obj;
		if (age != other.age)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public int getSalary() {
		return salary;
	}

	public void setSalary(int salary) {
		this.salary = salary;
	}

	public Date getHiredate() {
		return hiredate;
	}

	public void setHiredate(Date hiredate) {
		this.hiredate = hiredate;
	}

}
